home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
301_02
/
trigger.c
< prev
next >
Wrap
Text File
|
1989-12-28
|
39KB
|
1,143 lines
/*
HEADER: ;
TITLE: trigger.c
trigonometric implementations of the Borland Graphics Interface;
VERSION: 1.0;
DESCRIPTION: horsing around with trig functions and the Borland Graphics
Interface (BGI). This program was created and run on a Compaq Plus
and an IBM AT with a CGA card using Borland's TurboC 2.0. Routines
and variables with a single, initial capital letter (i.e. MainWindow())
are taken directly from the demo program accompanying TurboC 2.0.
The file CGA.BGI is likewise directly from the TurboC disk. In theory
by including a .BGI file for every conceivable combination of video
cards and allowing the program to auto detect the card one could make it
universally adaptable. In this case, however, the medium resolution
mode of the CGA card is forced. To allow for other cards, one could
initiate the sequence--
GraphDriver = DETECT;
initgraph( &GraphDriver, &GraphMode, "" );
but this would require all of the *.BGI files to be available on disk
or compiled within the program.
In addition several of the Borland routines are specific to IBM and
close compatibles so that the program is not very portable as written.
The Borland file 'graphics.h' contains the definitions for many of the
global variables specific for their functions (e.g. DETECT).
KEYWORDS: trig functions, BGI, Borland Graphics Interface, TurboC;
SYSTEM: MSDOS;
FILENAME: TRIGGER.C;
WARNINGS: Expects CGA card, will not run on monochrome
must have CGA.BGI on same directory or path to it;
SEE-ALSO: TRIGGER.EXE;
AUTHORS: Henry Pollock;
COMPILERS: TurboC 2.0;
*/
/*
-- TRIGGER.C horsing around with trig functions and the Borland Graphics
-- Interface (BGI).
-- Henry Pollock
-- Essex Center Drive
-- Peabody, MA 01960
-- 7/15/89
*/
#include <conio.h>
#include <dos.h>
#include <graphics.h>
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#define CTR_X_ORIGIN X_OFFSET + (MaxX - X_OFFSET)/2
#define CTR_Y_ORIGIN Y_OFFSET + (MaxY - Y_OFFSET)/2
#define ESC 0x1b /* Define the escape key */
#define FALSE 0 /* Define some handy constants */
#define OFF 0 /* Define some handy constants */
#define ON 1 /* Define some handy constants */
#define PI 3.14159 /* Define a value for PI */
#define SW_X_ORIGIN X_OFFSET
#define SW_Y_ORIGIN MaxY - Y_OFFSET
#define TRUE 1 /* Define some handy constants */
double AspectRatio; /* Aspect ratio of a pixel on the screen*/
int ErrorCode; /* Reports any graphics errors */
int GraphDriver; /* The Graphics device driver */
int GraphMode; /* The Graphics mode value */
int MaxColors; /* The maximum # of colors available */
int MaxX, MaxY; /* The maximum resolution of the screen */
int X_OFFSET = 0;
int Y_OFFSET = 0;
/*Routines from Borland Demo Disk */
int gprintf(int *xloc, int *yloc, char *fmt, ... );
void changetextstyle(int font, int direction, int charsize);
void DrawBorder(void);
void Initialize(void);
void MainWindow(char *header);
void StatusLine(char *msg);
/*Trig routines*/
int menu();
int scale_x(float *, float *);
int scale_y(float *, float *);
void asteroid();
void autoloid();
void circloid();
void cycloids();
void ctr_graph_plot();
void draw_circleoid(int *, int *, float *);
void get_params2(float *power);
void get_params8(char *cycloid, int *cusps);
void draw_roulette(char *cycloid, int *cusps);
void lissajous();
void logo();
void spiral();
void sw_graph_plot();
void tschirnhausen();
void roulettes();
void changetextstyle(int font, int direction, int charsize)
{
int ErrorCode;
graphresult(); /* clear error code */
settextstyle(font, direction, charsize);
ErrorCode = graphresult(); /* check result */
if( ErrorCode != grOk ){ /* if error occured */
closegraph();
printf(" Graphics System Error: %s\n", grapherrormsg( ErrorCode ) );
exit( 1 );
}
}
int gprintf( int *xloc, int *yloc, char *fmt, ... )
{
va_list argptr; /* Argument list pointer */
char str[140]; /* Buffer to build sting into */
int cnt; /* Result of SPRINTF for return */
va_start( argptr, format ); /* Initialize va_ functions */
cnt = vsprintf( str, fmt, argptr ); /* prints string to buffer */
outtextxy( *xloc, *yloc, str ); /* Send string in graphics mode */
*yloc += textheight( "H" ) + 2; /* Advance to next line */
va_end( argptr ); /* Close va_ functions */
return( cnt ); /* Return the conversion count */
}
void DrawBorder(void)
{
struct viewporttype vp;
setcolor( MaxColors - 1 ); /* Set current color to white */
setlinestyle( SOLID_LINE, 0, NORM_WIDTH );
getviewsettings( &vp );
rectangle( 0, 0, vp.right-vp.left, vp.bottom-vp.top );
}
void MainWindow( char *header )
{
int height;
cleardevice(); /* Clear graphics screen */
setcolor( MaxColors - 1 ); /* Set current color to white */
setviewport( 0, 0, MaxX, MaxY, 1 ); /* Open port to full screen */
height = textheight( "H" ); /* Get basic text height */
changetextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );
settextjustify( CENTER_TEXT, TOP_TEXT );
outtextxy( MaxX/2, 2, header );
setviewport( 0, height+4, MaxX, MaxY-(height+4), 1 );
DrawBorder();
setviewport( 1, height+5, MaxX-1, MaxY-(height+5), 1 );
}
void Initialize(void)
{
int xasp, yasp; /* Used to read the aspect ratio*/
GraphDriver = CGA; /* force cga */
GraphMode = CGAC1; /* cyan,magenta,white */
initgraph( &GraphDriver, &GraphMode, "" );
ErrorCode = graphresult(); /* Read result of initialization*/
if( ErrorCode != grOk ){ /* Error occured during init */
printf(" Graphics System Error: %s\n", grapherrormsg( ErrorCode ) );
exit( 1 );
}
MaxColors = getmaxcolor() + 1; /* Read maximum number of colors*/
MaxX = getmaxx();
MaxY = getmaxy(); /* Read size of screen */
getaspectratio( &xasp, &yasp ); /* read the hardware aspect */
AspectRatio = (double)xasp / (double)yasp; /* Get correction factor */
}
void StatusLine( char *msg )
{
int height;
setviewport( 0, 0, MaxX, MaxY, 1 ); /* Open port to full screen */
setcolor( MaxColors - 1 ); /* Set current color to white */
changetextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );
settextjustify( CENTER_TEXT, TOP_TEXT );
setlinestyle( SOLID_LINE, 0, NORM_WIDTH );
setfillstyle( EMPTY_FILL, 0 );
height = textheight( "H" ); /* Detemine current height */
bar( 0, MaxY-(height+4), MaxX, MaxY );
rectangle( 0, MaxY-(height+4), MaxX, MaxY );
outtextxy( MaxX/2, MaxY-(height+2), msg );
setviewport( 1, height+5, MaxX-1, MaxY-(height+5), 1 );
}
/*#################################################*/
void main() {
int menu_nbr;
char again = 'y';
Initialize();
while (again == 'y') {
restorecrtmode();
clrscr();
logo();
menu_nbr = menu();
switch (menu_nbr) {
case 1:
autoloid();
break;
case 2:
circloid();
break;
case 3:
asteroid();
break;
case 4:
spiral();
break;
case 5:
lissajous();
break;
case 6:
tschirnhausen();
break;